package com.zahb.qadx.ui.adapter;

import com.chad.library.adapter.base.BaseNodeAdapter;
import com.chad.library.adapter.base.entity.node.BaseNode;
import com.zahb.qadx.model.CurriculumChapter;

import org.jetbrains.annotations.NotNull;

import java.util.List;

/**
 * Created by Zdw on 2020/10/21 16:20
 * 课程目录树
 */
public class ChapterAdapter extends BaseNodeAdapter {

    private CurriculumChapter curriculumChapter; // 播放项
    private CurriculumChapter preCurriculumChapter; // 之前播放项

    public CurriculumChapter getCurriculumChapter() {
        return curriculumChapter;
    }

    public void setCurriculumChapter(CurriculumChapter curriculumChapter) {
        this.curriculumChapter = curriculumChapter;
    }

    public CurriculumChapter getPreCurriculumChapter() {
        return preCurriculumChapter;
    }

    public void setPreCurriculumChapter(CurriculumChapter preCurriculumChapter) {
        this.preCurriculumChapter = preCurriculumChapter;
    }

    public ChapterAdapter() {
        addNodeProvider(new ChapterProviderStart());
        addNodeProvider(new ChapterProviderMiddle());
        addNodeProvider(new ChapterProviderEnd());
    }

    @Override
    protected int getItemType(@NotNull List<? extends BaseNode> list, int i) {
        BaseNode baseNode = list.get(i);
        if (baseNode instanceof CurriculumChapter) {
            CurriculumChapter chapter = (CurriculumChapter) baseNode;
            if (chapter.getParent() == null) {
                if (chapter.getChildList() != null && chapter.getChildList().size() > 0)
                    return 0;// 首级
                else
                    return 2;// 末级
            } else {
                if (chapter.getChildList() != null && chapter.getChildList().size() > 0)
                    return 1;// 中间级
                else
                    return 2;// 末级
            }
        }
        return -1;
    }

}
